package com.study;


import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.study.dao.UserDao;
import com.study.service.UserService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.sql.Connection;

public class demo1 {
	@Test
	public void testC3PO() throws Exception{
		//创建数据源
		ComboPooledDataSource dataSource = new ComboPooledDataSource();

		//设置数据库连接参数
		dataSource.setDriverClass("com.mysql.jdbc.Driver");
		dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/test");
		dataSource.setUser("root");
		dataSource.setPassword("root");
		System.out.println(dataSource);
		//获取连接对象
		Connection connection = dataSource.getConnection();
		System.out.println(connection);
	}
	@Test
	public void test5(){
		ApplicationContext applicationContext =
				new ClassPathXmlApplicationContext("applicationContext.xml");
//		UserDao userDao1 = (UserDao) applicationContext.getBean("userDao1");
//		UserDao userDao2 = (UserDao) applicationContext.getBean("userDao2");
//		UserDao userDao3 = (UserDao) applicationContext.getBean("userDao3");
//		UserDao userDao4 = (UserDao) applicationContext.getBean("userDao4");
//		System.out.println(userDao1);
//		System.out.println(userDao2);
//		System.out.println(userDao3);
//		System.out.println(userDao4);
//		userDao1.save();
//		userDao2.save();
//		userDao3.save();
//		userDao4.save();

	}
	@Test
	public void test4(){
		ApplicationContext applicationContext =
				new ClassPathXmlApplicationContext("applicationContext.xml");
		UserDao userDao = (UserDao) applicationContext.getBean("userDao3");
//		UserDao userDao = applicationContext.getBean(UserDao.class);
		userDao.save();
	}
	@Test
	public void test3(){
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
		UserDao userDao = (UserDao) applicationContext.getBean("userDao3");
		userDao.toString();
	}
	@Test
	public void test1(){
		ApplicationContext applicationContext = new
				ClassPathXmlApplicationContext("applicationContext.xml");
//		UserDao userDao = (UserDao) applicationContext.getBean("userDao1");
		UserDao userDao2 = (UserDao) applicationContext.getBean("userDao2");
//
//		userDao.toString();
		userDao2.toString();

//		UserDao userDao2 = (UserDao) applicationContext.getBean("userDao1");
//		System.out.println(userDao);
//		System.out.println(userDao2);
//		userDao.save();
//		userDao.init();
//		userDao.destroy();
	}
	@Test
	public void test2(){
		ApplicationContext applicationContext =
				new ClassPathXmlApplicationContext("applicationContext.xml");
		UserService userService = (UserService) applicationContext.getBean("userService2");
//		userService.save();
	}
}


